﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using MvcAtletIS.Models;

namespace MvcAtletIS.Areas.MyClub.Controllers
{
    [Authorize(Roles = "Users")]
    public class ClubsController : Controller
    {
        atletisEntities db = new atletisEntities();
                
        // GET: /MyClub/Clubs/
        public ActionResult Index()
        {
            return View();
        }

        // GET: /MyClub/Clubs
        public ActionResult Edit()
        {
            Clubs clubs = db.Clubs.SingleOrDefault(c => c.ID == User.Identity.Name);
            if (clubs == null)
            {
                return HttpNotFound();
            }
            ViewBag.ClubsGroupsID = new SelectList(db.ClubsGroups, "ID", "Name", clubs.ClubsGroupsID);
            return View(clubs);
        }

        // POST: /Clubs/EditClub/5
        [HttpPost]
        public ActionResult Edit(Clubs clubs)
        {
            if (ModelState.IsValid)
            {
                db.Clubs.Attach(clubs);
                db.ObjectStateManager.ChangeObjectState(clubs, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index", "Home");
            }
            ViewBag.ClubsGroupsID = new SelectList(db.ClubsGroups, "ID", "Name", clubs.ClubsGroupsID);
            return View(clubs);
        }


    }
}
